package TableModels;

import Database.DBLoader;
import java.awt.Color;
import java.awt.Component;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class CellRendererRes extends DefaultTableCellRenderer {

    private DBLoader database;
    private int luColumn;
    private ArrayList<String> vect;

    public CellRendererRes(DBLoader database, int luColumn) {
        super();
        vect = new ArrayList<String>();
        this.database = database;
        this.luColumn = luColumn;
        try {
            ResultSet result = database.executeQuery("select * from App.COMENTARIO");
            while (result.next()) {
                vect.add(result.getString("LU"));
            }
        } catch (SQLException ex) {
        }
    }
    
    @Override
    public Component getTableCellRendererComponent(
            JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column) {

        Component component = super.getTableCellRendererComponent(
                table, value, isSelected, hasFocus, row, column);
        if (!isSelected) {
            String lu = table.getModel().getValueAt(row, luColumn).toString();
            if (vect.contains(lu)) {
                component.setBackground(Color.YELLOW);
            } else {
                component.setBackground(Color.WHITE);
            }

        }
        return component;
    }
}
